Skip to content

feat: allow updating already-registered coins via replaceExistingCoin - #9922

Merged
prajwalu142 merged 1 commit into
masterfrom
CSHLD-863-replace-existing-coin-fields
Oct 13, 2026
Merged

prajwalu142 merged 1 commit into
masterfrom
CSHLD-863-replace-existing-coin-fields

Conversation

@prajwalu142

@prajwalu142 prajwalu142 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

createTokenMapUsingTrimmedConfigDetails and createToken skip any coin
already present in the static coin map (statics wins), so an AMS payload
for an existing coin can never change its features without a statics
release and a consumer redeploy.

Goal

Let AMS payloads update already-registered coins for allowlisted fields
only, keeping identity/structural fields immutable, so feature changes
reach consumers without a statics release — without ever crashing the
registration process on a malformed payload.

Fix

  • New exported function replaceExistingCoin(token) in statics: replaces
    the registered entry with a frozen, prototype-preserving copy —
    existing values copied verbatim, features taken from the config. Full
    feature sets apply verbatim; delta-only configs merge onto the
    registered coin's CURRENT features (existing ∪ additionalFeatures −
    excludedFeatures), so statics-migration rows with empty deltas no-op.
    No-op returning the same registered object when nothing differs.
    Rebuilds all CoinMap indexes (name, id, alias, contract address, NFT
    collection).
  • Blocklist (alias, symbol, contractAddress): a payload claiming
    different values for a blocklisted field is ignored with a warning
    — the registered entry stays untouched; malformed updates never crash
    registration. name remains replaceable.
  • Wired at every isCoinPresentInCoinMap spot with the normal flow
    preserved (no loop breaks): createToken present branch;
    createTokenMapUsingConfigDetails loop (if/else — replaced entry
    re-pointed into BaseCoins); createTokenMapUsingTrimmedConfigDetails
    and createTokenUsingTrimmedConfigDetails. New-token paths reuse the
    existing getTokenFeatures helper instead of inline feature merges.

Testing

New replaceExistingCoin suite: replace + index rebuild, no-op on equal
features, delta merge with dedupe across repeated refreshes, verbatim
copy of existing values, blocklisted-field payloads ignored (registered
coin returned untouched), unregistered coin throws. Contract pin updated
to the new update semantics; builder tests passing configs for
already-registered coins restore touched entries so the global map stays
pristine across suites. Full statics suite 39324 passing / 0 failing;
tsc and eslint clean.

Ticket: CSHLD-863
🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

CSHLD-863

CSHLD-1957

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Unit tests are failing on Node 26.x (Current release line, non-blocking). This is not an LTS version yet, so it does not block merge, but it signals an incompatibility to fix before Node 26.x becomes LTS.

View run

@prajwalu142
prajwalu142 force-pushed the CSHLD-863-replace-existing-coin-fields branch 6 times, most recently from 53cca16 to 8ca89b8 Compare October 8, 2026 10:35
Comment thread modules/statics/src/map.ts Resolved
Comment thread modules/statics/src/map.ts Resolved
@prajwalu142
prajwalu142 force-pushed the CSHLD-863-replace-existing-coin-fields branch from 8ca89b8 to 8b99134 Compare October 8, 2026 12:06
Problem/goal:
createToken and the token map builders skip any coin already present in
the static coin map, so an AMS payload for an existing token can never
refresh its modifiable fields (features, fullName, decimalPlaces)
without a statics release. Goal: let AMS update known tokens while the
fields that define the asset stay immutable.

Implementation details:
- CoinMap.replace only swaps when the old and new records are both
  tokens and agree on id, symbol (prefix + suffix), contract address and
  alias. Otherwise the existing record is kept. Coins not yet in the map
  are still added.
- createToken no longer returns the stale static record. For a known
  token it constructs the token, calls coins.replace, and returns the
  record the map holds. A config that fails token validation keeps the
  existing record instead of throwing. The initializer switch moved into
  a private constructToken.
- createTokenMapUsingConfigDetails mirrors a refreshed token into its
  rebuilt map. The two trimmed-config gates now only skip known base
  chains; known tokens flow through the refresh path.

Verification:
Statics unit suite: 39324 passing, 0 failing. eslint on the changed
files: 0 errors. New replace tests cover a matching swap with index
lookups by name, id and contract address, and keeping the existing
record on a differing symbol, contract address, alias or id and for base
coins. The old precedence tests were rewritten to the new contract and
the AMS fixture suite restores the global coin map afterwards.

Ticket: CSHLD-863
@prajwalu142
prajwalu142 force-pushed the CSHLD-863-replace-existing-coin-fields branch from 8b99134 to 787e718 Compare October 9, 2026 12:10
@prajwalu142
prajwalu142 marked this pull request as ready for review October 13, 2026 09:21
@prajwalu142
prajwalu142 requested a review from a team as a code owner October 13, 2026 09:21
@prajwalu142
prajwalu142 merged commit ac9ca0a into master Oct 13, 2026
27 checks passed
prajwalu142 added a commit that referenced this pull request Oct 14, 2026
…-coin

Revert "feat: refresh known tokens via identity-guarded CoinMap.replace (#9922)"
prajwalu142 added a commit that referenced this pull request Oct 19, 2026
problem/goal
Re-land the AMS-driven refresh of already-registered coins that was
reverted from statics 2138 (#9970 reverting #9922). The original
implementation replaced any known coin matched by an AMS record,
including base chains, which swapped LightningCoin for DynamicCoin and
broke wallet-platform coin singletons on staging (CSHLD-1957).

implementation details
- createToken stays pure: known coins are returned untouched; unknown
  records build via constructToken (extracted from createToken).
- createTokenMapUsingConfigDetails owns the refresh: known tokens flow
  instead of being skipped, and the refreshed record is written through
  CoinMap.replace, which rejects same-id replacements that change the
  coin class (CoinClassMismatchError) or the immutable identity fields
  id, name, alias and contract address (CoinImmutableFieldsMismatchError).
  Known base chains never reach the refresh path.
- createTokenMapUsingTrimmedConfigDetails lets known tokens continue
  into feature enrichment and delegates the refresh to the config
  details builder.
- New tests pin the base-chain parity canary, the tlnbtc regression,
  refresh with class preservation, class-swap rejection, per-field
  identity rejection (id, name, alias, contract address), alias-drop
  fail-closed on builder refresh, and AMS feature updates flowing
  through while identity stays untouched.

verification
npx mocha test/unit/ in modules/statics: 39700 passing, 0 failing;
tsc --noEmit clean; eslint clean.

Ticket: CSHLD-863
prajwalu142 added a commit that referenced this pull request Oct 19, 2026
problem/goal
Re-land the AMS-driven refresh of already-registered coins that was
reverted from statics 2138 (#9970 reverting #9922). The original
implementation replaced any known coin matched by an AMS record,
including base chains, which swapped LightningCoin for DynamicCoin and
broke wallet-platform coin singletons on staging (CSHLD-1957).

implementation details
- createToken stays pure: known coins are returned untouched; unknown
  records build via constructToken (extracted from createToken).
- createTokenMapUsingConfigDetails owns the refresh: known tokens flow
  instead of being skipped, and the refreshed record is written through
  CoinMap.replace, which rejects same-id replacements that change the
  coin class (CoinClassMismatchError) or the immutable identity fields
  id, name, alias and contract address (CoinImmutableFieldsMismatchError).
  Known base chains never reach the refresh path.
- createTokenMapUsingTrimmedConfigDetails lets known tokens continue
  into feature enrichment and delegates the refresh to the config
  details builder.
- New tests pin the base-chain parity canary, the tlnbtc regression,
  refresh with class preservation, class-swap rejection, per-field
  identity rejection (id, name, alias, contract address), alias-drop
  fail-closed on builder refresh, and AMS feature updates flowing
  through while identity stays untouched.

verification
npx mocha test/unit/ in modules/statics: 39700 passing, 0 failing;
tsc --noEmit clean; eslint clean.

Ticket: CSHLD-863
prajwalu142 added a commit that referenced this pull request Oct 19, 2026
problem/goal
Re-land the AMS-driven refresh of already-registered coins that was
reverted from statics 2138 (#9970 reverting #9922). The original
implementation replaced any known coin matched by an AMS record,
including base chains, which swapped LightningCoin for DynamicCoin and
broke wallet-platform coin singletons on staging (CSHLD-1957).

implementation details
- createToken stays pure: known coins are returned untouched; unknown
  records build via constructToken (extracted from createToken).
- createTokenMapUsingConfigDetails owns the refresh: known tokens flow
  instead of being skipped, and the refreshed record is written through
  CoinMap.replace, which rejects same-id replacements that change the
  coin class (CoinClassMismatchError) or the immutable identity fields
  id, name, alias and contract address (CoinImmutableFieldsMismatchError).
  Known base chains never reach the refresh path.
- createTokenMapUsingTrimmedConfigDetails lets known tokens continue
  into feature enrichment and delegates the refresh to the config
  details builder.
- New tests pin the base-chain parity canary, the tlnbtc regression,
  refresh with class preservation, class-swap rejection, per-field
  identity rejection (id, name, alias, contract address), alias-drop
  fail-closed on builder refresh, and AMS feature updates flowing
  through while identity stays untouched.

verification
npx mocha test/unit/ in modules/statics: 39700 passing, 0 failing;
tsc --noEmit clean; eslint clean.

Ticket: CSHLD-863
prajwalu142 added a commit that referenced this pull request Oct 19, 2026
problem/goal
Re-land the AMS-driven refresh of already-registered coins that was
reverted from statics 2138 (#9970 reverting #9922). The original
implementation replaced any known coin matched by an AMS record,
including base chains, which swapped LightningCoin for DynamicCoin and
broke wallet-platform coin singletons on staging (CSHLD-1957).

implementation details
- createToken stays pure: known coins are returned untouched; unknown
  records build via constructToken (extracted from createToken).
- createTokenMapUsingConfigDetails owns the refresh: known tokens flow
  instead of being skipped, and the refreshed record is written through
  CoinMap.replace, which rejects same-id replacements that change the
  coin class (CoinClassMismatchError) or the immutable identity fields
  id, name, alias and contract address (CoinImmutableFieldsMismatchError).
  Known base chains never reach the refresh path.
- createTokenMapUsingTrimmedConfigDetails lets known tokens continue
  into feature enrichment and delegates the refresh to the config
  details builder.
- New tests pin the base-chain parity canary, the tlnbtc regression,
  refresh with class preservation, class-swap rejection, per-field
  identity rejection (id, name, alias, contract address), alias-drop
  fail-closed on builder refresh, and AMS feature updates flowing
  through while identity stays untouched.

verification
npx mocha test/unit/ in modules/statics: 39700 passing, 0 failing;
tsc --noEmit clean; eslint clean.

Ticket: CSHLD-863
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants